<?php

class App_Helper_Table_Row {
   
   public $cells;
   private $attribs = array();
   public $rowid;
   public $isHeader = false;
   
   public function __construct($cells=array(), $attribs=array(), $rowid="", $isHeader=false) {
      $this->cells = $cells;
      $this->attribs = $attribs;
      $this->rowid = $rowid;
      $this->isHeader = $isHeader;
   }
   
   
   public function addHeader($data, $attribs=array(), $cellid) {
      $this->addCell($data, $attribs, $cellid, true);
   }
   
   public function addCell($data, $attribs=array(), $cellid="", $isHeader=false) {      
      if($data instanceof App_Helper_Table_Cell) {
         $data->isHeader = $isHeader;
         $cell = $data;
      } else {
         $cell = new App_Helper_Table_Cell($data, $attribs, $cellid, $isHeader);
      }
      if(strlen($cell->cellid)) {
         $this->cells[$cellid] = $cell;
      } else {
         $this->cells[] = $cell;
      }
   }
   
   public function __toString() {
      $str = "<tr";
      foreach($this->attribs as $key => $val)  {
         $str .= " $key=\"$val\"";
      }
      $str .= ">";
      foreach($this->cells as $cell) {
         $str .= $cell;
      }
      $str .= "</tr>\r\n";
      return $str;
   }
}